<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 连接数配置详解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=NotoSans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
            color: white;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 6px;
            padding: 1rem;
            position: relative;
        }
        .code-block .copy-btn {
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.2s;
        }
        .code-block .copy-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }
        .highlight {
            background-color: rgba(110, 142, 251, 0.1);
            padding: 0.2rem 0.4rem;
            border-radius: 4px;
            font-weight: 600;
        }
        a {
            color: #6e8efb;
            transition: color 0.2s;
        }
        a:hover {
            color: #4f6de4;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero min-h-screen flex items-center justify-center py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 font-serif">Spring Boot 连接数配置</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto">深入理解服务器性能调优的关键参数</p>
            <div class="flex justify-center space-x-4">
                <a href="#content" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-gray-100 transition-all">开始探索</a>
                <a href="#visualization" class="bg-transparent border-2 border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:text-indigo-600 transition-all">可视化图表</a>
            </div>
            <div class="mt-16 animate-bounce">
                <i class="fas fa-chevron-down text-2xl text-white opacity-70"></i>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section id="content" class="py-20 bg-white">
        <div class="container mx-auto px-6 max-w-4xl">
            <div class="mb-12">
                <h2 class="text-3xl font-bold mb-4 text-gray-800 font-serif">Spring Boot 默认连接数配置</h2>
                <p class="text-gray-600 mb-6">Spring Boot 默认允许的最大连接数取决于所使用的 Web 服务器。对于嵌入式 Tomcat，默认最大连接数是 <span class="highlight">10000</span>，而最大线程数是 <span class="highlight">200</span>。这些值可以根据需求在配置文件中进行调整。</p>
                
                <div class="grid md:grid-cols-2 gap-6 mb-12">
                    <div class="card bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-xl">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 p-3 rounded-full mr-4">
                                <i class="fas fa-plug text-blue-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">最大连接数</h3>
                        </div>
                        <p class="text-gray-600"><code class="font-mono bg-blue-100 px-1 rounded">maxConnections</code> 默认值通常是 <span class="highlight">10000</span>，表示允许的最大并发连接数。</p>
                    </div>
                    
                    <div class="card bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                        <div class="flex items-center mb-4">
                            <div class="bg-purple-100 p-3 rounded-full mr-4">
                                <i class="fas fa-code-branch text-purple-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">最大线程数</h3>
                        </div>
                        <p class="text-gray-600"><code class="font-mono bg-purple-100 px-1 rounded">maxThreads</code> 默认值通常是 <span class="highlight">200</span>，表示能够同时处理的请求线程数。</p>
                    </div>
                </div>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-bold mb-4 text-gray-800 font-serif">Tomcat 配置示例</h3>
                    <p class="text-gray-600 mb-4">这两个参数可以通过配置文件进行调整，例如在 <code class="font-mono bg-gray-100 px-1 rounded">application.properties</code> 或 <code class="font-mono bg-gray-100 px-1 rounded">application.yml</code> 中配置：</p>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="code-block">
                            <button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy mr-1"></i>复制</button>
                            <pre><code># 设置 Tomcat 最大连接数和最大线程数
server.tomcat.max-connections=10000
server.tomcat.max-threads=200</code></pre>
                        </div>
                        <div class="code-block">
                            <button class="copy-btn" onclick="copyCode(this)"><i class="fas fa-copy mr-1"></i>复制</button>
                            <pre><code># 设置 Tomcat 最大连接数和最大线程数
server:
  tomcat:
    max-connections: 10000
    max-threads: 200</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="mb-12">
                    <h3 class="text-2xl font-bold mb-4 text-gray-800 font-serif">其他 Web 服务器的配置</h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="card bg-white p-6 rounded-xl border border-gray-200">
                            <h4 class="font-bold text-lg mb-3 flex items-center">
                                <i class="fas fa-server text-blue-500 mr-2"></i>
                                Jetty
                            </h4>
                            <p class="text-gray-600">Jetty 的 <code class="font-mono bg-gray-100 px-1 rounded">maxThreads</code> 默认值通常是 <span class="highlight">200</span>。</p>
                        </div>
                        <div class="card bg-white p-6 rounded-xl border border-gray-200">
                            <h4 class="font-bold text-lg mb-3 flex items-center">
                                <i class="fas fa-server text-purple-500 mr-2"></i>
                                Undertow
                            </h4>
                            <p class="text-gray-600">Undertow 的 <code class="font-mono bg-gray-100 px-1 rounded">io-threads</code> 和 <code class="font-mono bg-gray-100 px-1 rounded">worker-threads</code> 会影响最大连接数。</p>
                        </div>
                        <div class="card bg-white p-6 rounded-xl border border-gray-200">
                            <h4 class="font-bold text-lg mb-3 flex items-center">
                                <i class="fas fa-info-circle text-yellow-500 mr-2"></i>
                                默认值说明
                            </h4>
                            <p class="text-gray-600">默认的 <code class="font-mono bg-gray-100 px-1 rounded">io-threads</code> 根据 CPU 核心数动态计算，而 <code class="font-mono bg-gray-100 px-1 rounded">worker-threads</code> 的默认值是 <span class="highlight">200</span>。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section id="visualization" class="py-20 bg-gray-50">
        <div class="container mx-auto px-6 max-w-4xl">
            <h2 class="text-3xl font-bold mb-12 text-center text-gray-800 font-serif">服务器连接参数可视化</h2>
            
            <div class="bg-white p-6 rounded-xl shadow-md mb-12">
                <h3 class="text-xl font-bold mb-4 text-gray-800">Spring Boot Web 服务器参数比较</h3>
                <div class="mermaid">
                    graph TD
                        A[Spring Boot Web 服务器] --> B[Tomcat]
                        A --> C[Jetty]
                        A --> D[Undertow]
                        
                        B --> B1[maxConnections: 10000]
                        B --> B2[maxThreads: 200]
                        
                        C --> C1[maxThreads: 200]
                        
                        D --> D1[io-threads: CPU核心数]
                        D --> D2[worker-threads: 200]
                </div>
            </div>
            
            <div class="card bg-gradient-to-r from-indigo-500 to-purple-600 p-8 rounded-xl text-white">
                <div class="flex items-start">
                    <div class="mr-6 text-4xl">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <div>
                        <h3 class="text-xl font-bold mb-2">性能调优建议</h3>
                        <p class="opacity-90">在实际生产环境中，这些默认值可能需要根据应用的具体负载情况进行调整。过高的连接数和线程数可能会导致资源耗尽，而过低则可能限制应用的吞吐量。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="container mx-auto px-6 text-center">
            <div class="mb-6">
                <h2 class="text-2xl font-bold">技术小馆</h2>
                <p class="text-gray-400 mt-2">专注于高质量技术内容分享</p>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="inline-block bg-indigo-600 hover:bg-indigo-700 px-6 py-2 rounded-lg transition-colors duration-200">访问语雀主页</a>
            </div>
            <div class="mt-8 text-gray-500 text-sm">
                &copy; 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true
            }
        });
        
        // Copy code function
        function copyCode(button) {
            const codeBlock = button.parentElement;
            const code = codeBlock.querySelector('code').textContent;
            navigator.clipboard.writeText(code).then(() => {
                button.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';
                setTimeout(() => {
                    button.innerHTML = '<i class="fas fa-copy mr-1"></i>复制';
                }, 2000);
            });
        }
        
        // Smooth scrolling
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>